<!-----------------------------------------------------------------------------
-- 2013 All rights reserved
-- Project codename: FROMCOMA 
-- Date: 20sept2013
-- Author: A.A
-- Description: category managing page. 
-------------------------------------------------------------------------------
-- Changelog:
-- v0.1:	we're off.
-- 
------------------------------------------------------------------------------>
<?php 
/* Connecting to MySQL */
require 'sqlconn.inc.php';

/* Table */
$table = "categories";
/* Query */
$result = mysql_query("SELECT * FROM $table ORDER BY id ASC");
/* Adding a category script */
if( isset($_POST['catchange']) ) // checking if form was submitted
{
	$sql = "INSERT INTO $table (id, name) VALUES ('$_POST[category]','$_POST[name]')";
    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error()); 
	//echo "Category: $_POST[name] added!";
	header('Location: category.php');
}


?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>FROMCOMA</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" type="text/css" href="style.css" />

</head>
<body>
<h1>Catories Page.</h1>
<h2> Categories list:</h2>
<?php	

while($row = mysql_fetch_array($result))
	{
	$id = $row['id'];
	$name = $row['name'];
	echo "$id - $name <br>";
	}
	
?>
<h2>Add a category</h2>	
<form action="category.php" enctype="multipart/form-data" method="post">
ID:<input name="category" size="5" type="text" />
<br>
NAME: <input name="name" size="30" type="text" />

<input name="catchange" type="submit" value="Add category" />
</form>
</body>
</html>